package com.graduate.cec.controller;

import com.graduate.cec.common.JsonPage;
import com.graduate.cec.common.JsonResult;
import com.graduate.cec.pojo.dto.CarouselSimpleDTO;
import com.graduate.cec.pojo.dto.CategorySimpleDTO;
import com.graduate.cec.pojo.entity.Category;
import com.graduate.cec.pojo.vo.CarouselVO;
import com.graduate.cec.pojo.vo.CategoryVO;
import com.graduate.cec.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/category",produces = "application/json;charset=utf-8")
@Api(tags = "分类管理")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    /****************        增       ******************************************************************/
    @GetMapping("/insert-category")
    @ApiOperation("增加分类")
    public JsonResult<Void> insertCategory(Category category){
        categoryService.insertCategory(category);
        log.info("category:{}",category);
        return JsonResult.ok("插入成功");
    }



    /****************        删       ******************************************************************/
    @GetMapping("/delete-by-keys/{ids}")
    @ApiOperation("通过主键删除分类")
    public JsonResult<Void> deleteByKeys(@PathVariable("ids") List<Long> ids){
        log.info("ids:{}", ids);
        categoryService.deleteByKeys(ids);
        return JsonResult.ok("删除成功");
    }


    /****************        改       ******************************************************************/
    @PostMapping("/update-by-key")
    @ApiOperation("通过主键修改分类内容")
    public JsonResult<Void> updateByKey(@RequestBody Category category){
        log.info("category:{}",category);
        categoryService.updateByKey(category);
        return JsonResult.ok("修改成功");
    }


    /****************        查        ******************************************************************/

    /**
     * 查询所有列表
     * @return JsonResult<List<CategoryVO>>
     */
    @GetMapping("/get-category-by-id")
    @ApiOperation("查询分类通过id")
    public JsonResult<List<Category>> getCategoryById(Long id){
        return JsonResult.ok("查询成功",categoryService.getCategoryById(id));
    }


    /**
     * 查询所有列表
     * @return JsonResult<List<CategoryVO>>
     */
    @GetMapping("/get-all-list")
    @ApiOperation("查询全部列表")
    public JsonResult<List<Category>> getAllList(){
        return JsonResult.ok("查询成功",categoryService.getAllList());
    }



    @GetMapping("/get-list-by-example")
    @ApiOperation("通过一定条件()查找列表")
    public JsonResult<JsonPage<CategoryVO>> getListByExample(CategorySimpleDTO categorySimpleDTO){
        log.info("categorySimpleDTO:{}", categorySimpleDTO);
        JsonPage<CategoryVO> jsonPage = categoryService.getListByExample(categorySimpleDTO);
        return JsonResult.ok("查询成功",jsonPage);
    }


}
